package com.turtle.learning.auth.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 安全服务工具类
 *
 * @author turtle
 * date: 2020-05-07
 */
public class SecurityUtil {

    /**
     * 密码加密
     *
     * @param password 明文密码
     * @return 加密密码
     */
    public static String encryptPassword(String password) {

        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.encode(password);
    }

    /**
     * 判断两个密码是否相同
     *
     * @param rawPassword    原始密码
     * @param encodePassword 加密密码
     * @return Boolean
     */
    public static Boolean confirmPassword(String rawPassword, String encodePassword) {
        BCryptPasswordEncoder cryptPasswordEncoder = new BCryptPasswordEncoder();
        return cryptPasswordEncoder.matches(rawPassword, encodePassword);
    }
}
